<%--by金刚天使葫芦娃--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.web.my12306.pojo.User,com.web.my12306.util.*" %>
<html>
<head><html>
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link rel="stylesheet" type="text/css" href="js/util/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="js/util/easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="js/util/easyui/demo/demo.css">
    <script type="text/javascript" src="js/util/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="js/util/easyui/jquery.easyui.min.js"></script>
</head>
<body>
<div style="margin:20px 0;"></div>
<div class="easyui-panel" title="修改密码" style="width:600px">
    <%--<form id="editPassword" name="editPassword" method="post" action="User/editPassword">--%>
    <div style="padding:10px 60px 20px 60px">
        <table cellpadding=3>
            <tr>
                <td>用户中心—-修改密码</td>
                <td></td>
            </tr>
            <tr>
                <td><p>请输入原密码：</p></td>
                <td><input type="password" class="txt01 easyui-validatebox"
                           required="true" validType="password"
                           id="oldPassword" name="oldPassword"/>
                </td>
            </tr>
            <tr>
                <td>新密码：</td>
                <td><input type="Password" class="txt01 easyui-validatebox"
                           required="true" validType="password"
                           id="txtNewPass" name="txtNewPass"/>
                </td>
            </tr>
            <tr>
                <td>确认密码：</td>
                <td><input type="Password" class="txt01 easyui-validatebox"
                           required="true" validType="password"
                           id="txtRePass" name="txtRePass"/>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <% String msg = (String) request.getAttribute("msg");
                        if (msg != null) {
                    %>
                    <%= msg %>
                    <%
                        }
                    %>
                </td>
            </tr>
        </table>
        <div region="south" border="false" style="text-align: right; height: 30px; line-height: 30px;">
            <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" href="javascript:void(0)">确定</a>
            <a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel" href="javascript:void(0)">取消</a>
        </div>
    </div>
    <%--</form>--%>
</div>
<script type="text/javascript">
    $.extend($.fn.validatebox.defaults.rules, {
        password: {
            validator: function (value, param) {
                return /^[a-z0-9_.]{6,20}$/gi.test(value);
            },
            message: '密码是6-20的字符组合（不包含除“_”“.”以外的特殊字符）'
        }
    });

    //为“确定”按钮定事件--(失败)
    $("#btnEp").click(function () {
        //进行表单校验
//        var v = $("#password").form("validate");//对应表单中的所有输入框进行校验
//        if (v) {//表单校验通过
        //判断两次输入是否一致
        var oldpassword = $("#oldPassword").val();
        var txtNewPass = $("#txtNewPass").val();
        var txtRePass = $("#txtRePass").val();
        if (txtNewPass == txtRePass) {
            //输入一致，发送ajax请求，修改当前用户的密码绑
            var url = "User/editPassword";
            $.post(url, {"oldPassword": oldpassword,"txtNewPass":txtNewPass}, function (data) {
                if (data == '1') {
                    //修改密码成功
                    $.messager.alert("提示信息", "密码修改成功！", "info");
                } else {
                    //修改失败
                    $.messager.alert("提示信息", "原密码不正确！密码修改失败！", "warning");
                }
                //关闭修改密码的窗口
                $("#editPwdWindow").window("close");
            });
        } else {
            //输入不一致，提示用户输入不一致
            $.messager.alert("提示信息", "两次输入密码不一致！", "warning");
        }
    });
</script>
</body>
</html>
